package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatChat;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 12.
 */
@Repository
public class PushChatChatDaoImpl extends SqlSessionDaoSupport implements PushChatChatDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatChatDaoImpl.class);

    /**
     * 채팅방 중복 확인을 한다. 참여자가 2명일때만 확인한다.
     *
     * @param pushChatChat
     * @return
     */
    @Override
    public PushChatChat selectChatDuplicate(PushChatChat pushChatChat) {
        logger.info("selectChatDuplicate");
        return (PushChatChat)this.getSqlSession().selectOne("PUSHCHAT_CHAT.selectChatDuplicate", pushChatChat);
    }

    /**
     * 채팅방을 개설 한다.
     *
     * @param pushChatChat
     */
    @Override
    public void registerChat(PushChatChat pushChatChat) {
        logger.info("registerChat");
        this.getSqlSession().insert("PUSHCHAT_CHAT.registerChat", pushChatChat);
    }

    /**
     * 채팅방 정보를 가져 온다. 채팅방을 개설할때 호출한다.
     *
     * @param pushChatChat
     * @return
     */
    @Override
    public PushChatChat selectChatInformation(PushChatChat pushChatChat) {
        logger.info("selectChatInformation");
        return (PushChatChat)this.getSqlSession().selectOne("PUSHCHAT_CHAT.selectChatInformation", pushChatChat);
    }

    /**
     * 채팅방 목록을 가져 온다.
     *
     * @param pushChatChat
     * @return
     */
    @Override
    public List<PushChatChat> selectChatList(PushChatChat pushChatChat) {
        logger.info("selectChatList");
        return this.getSqlSession().selectList("PUSHCHAT_CHAT.selectChatList", pushChatChat);
    }

    /**
     * 채팅방을 비활성화 한다.
     *
     * @param pushChatChat
     */
    @Override
    public void updateDeactivateChat(PushChatChat pushChatChat) {
        logger.info("updateDeactivateChat");
        this.getSqlSession().update("PUSHCHAT_CHAT.updateDeactivateChat", pushChatChat);
    }
}
